package com.ibiaoke.customer.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.customer.consts.TradeStatusConsts;
import com.ibiaoke.customer.entity.TradeRecorder;
import com.ibiaoke.customer.entity.TradeRecorderExample;
import com.ibiaoke.customer.mapper.TradeRecorderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TradeRecorderDao extends BaseDao<TradeRecorder, TradeRecorderExample, Integer, TradeRecorderMapper> {

    @Autowired
    private TradeRecorderMapper tradeRecorderMapper;

    @Override
    public TradeRecorderMapper getMapper() {
        return tradeRecorderMapper;
    }

    public TradeRecorder getTradeRecorder(String tradeNo) {
        TradeRecorderExample example = new TradeRecorderExample();
        example.createCriteria().andTradeNoEqualTo(tradeNo);
        return getByExample(example);
    }

    public int updateToSuccess(Integer tradeId, Integer payType, String transactionNo) {
        TradeRecorder recorder = new TradeRecorder();
        recorder.setTradeId(tradeId);
        recorder.setPayType(payType);
        recorder.setTransactionNo(transactionNo);
        recorder.setStatus(TradeStatusConsts.SUCCESS);
        return updateByPrimaryKeySelective(recorder);
    }
}
